// https://nuxt.com/docs/api/configuration/nuxt-config
import AutoImport from 'unplugin-auto-import/vite';
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers';
import Components from 'unplugin-vue-components/vite';

// eslint-disable-next-line node/prefer-global/process
const PROXY_PREFIX = process.env.NUXT_PROXY_PREFIX || '/server';

export default defineNuxtConfig({
  compatibilityDate: '2025-05-15',
  devtools: { enabled: true },
  typescript: {
    typeCheck: false,
  },
  runtimeConfig: {
    public: {
      PROXY_PREFIX,
    },
    // eslint-disable-next-line node/prefer-global/process
    DEFAULT_THEME_MODEL: process.env.NUXT_DEFAULT_THEME_MODEL || 'light',
  },
  modules: [
    '@nuxtjs/tailwindcss',
    'nuxtjs-naive-ui',
    '@pinia/nuxt',
    'nuxt-lodash',
    '@nuxtjs/i18n',
    '@nuxt/eslint',
    'dayjs-nuxt',
    '@vueuse/nuxt',
  ],
  lodash: {
    prefix: '_',
  },
  i18n: {
    locales: [
      {
        code: 'en',
        language: 'en-US',
        name: 'English',
        file: 'en.json',
      },
      {
        code: 'zh',
        language: 'zh-CN',
        name: '中文',
        file: 'zh.json',
      },
    ],
    lazy: true,
    langDir: 'locales',
    defaultLocale: 'zh',
    strategy: 'prefix_except_default',
    detectBrowserLanguage: {
      useCookie: true,
      cookieKey: 'i18n_redirected',
      redirectOn: 'root',
      alwaysRedirect: true,
      fallbackLocale: 'zh',
    },
  },
  css: ['normalize.css', '~/assets/css/reset.css', '~/assets/css/globals.css'],
  vite: {
    plugins: [
      AutoImport({
        imports: [
          {
            'naive-ui': [
              'useDialog',
              'useMessage',
              'useNotification',
              'useLoadingBar',
            ],
          },
          {
            dayjs: [['default', 'dayjs']],
          },
        ],
        exclude: ['@vueuse/nuxt'],
      }),
      Components({
        resolvers: [NaiveUiResolver()],
      }),
    ],
  },
  nitro: {
    routeRules: {
      [`${PROXY_PREFIX}/**`]: {
        // eslint-disable-next-line node/prefer-global/process
        proxy: process.env.NUXT_SERVER_URL || 'http://localhost:8080', // 匹配子路径
      },
    },
  },
});
